package thread;

public class MyObject {
    synchronized public void method() {
        System.out.println("Thread--------"+Thread.currentThread().getName());
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public void method2(){
        System.out.println("Thread------------"+Thread.currentThread().getName()+"method2");
    }
    public void method3(String s){
        synchronized (s){
            System.out.println("Thread------------"+Thread.currentThread().getName()+"第一次输出："+s);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("Thread------------"+Thread.currentThread().getName()+"第二次输出："+s);
    }
}
